package com.tzu.gateway;

import com.tzu.gateway.bean.GatewayConfig;
import lombok.extern.log4j.Log4j2;
import thirdpart.checksum.ByteCheckSum;
import thirdpart.codec.BodyCodec;

import java.io.FileInputStream;
import java.io.InputStream;

/**
 * @Author: Tzu
 * @Date: 2020/11/18 21:04
 * @Version: 1.0
 * @Description:
 */
@Log4j2
public class GatewayStartup {

    public static void main(String[] args) throws Exception {

        GatewayConfig config = new GatewayConfig();

        //1、加载配置文件
        String configFileName = "gateway.xml";
        InputStream inputStream ;
        try {
            // 配置文件在jar包同级目录下
            inputStream = new FileInputStream(System.getProperty("user.dir") + "\\" + configFileName);
            log.info("gateway.xml exist in jar path");
        }catch (Exception e){
            // 配置文件在jar包里面
            inputStream = GatewayStartup.class.getResourceAsStream("/" + configFileName);
            log.info("gateway.xml exist in jar file");
        }

        config.initConfig(inputStream);
//        config.initConfig(GatewayStartup.class.getResource("/").getPath()
//                + configFileName);

        //2、加载工具类
        config.setCs(new ByteCheckSum());
        config.setBodyCodec(new BodyCodec());
        //3、启动网关
        config.startup();
    }
}
